package com.helloandroid.activesitting.bc;

import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;

import com.helloandroid.activesitting.ApplicationObject;

public class MotionConnector implements SensorEventListener {

	private final SensorManager _sensorManager;
	private final Sensor _acceleroMeter;
	private float[] _axis = {0,0,0};

	public MotionConnector() {
		this._sensorManager = (SensorManager) ApplicationObject.ApplicationContext
				.getSystemService(Context.SENSOR_SERVICE);
		this._acceleroMeter = this._sensorManager
				.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
		this._sensorManager.registerListener(this, this._acceleroMeter,
				SensorManager.SENSOR_DELAY_NORMAL);
	}

	public void Stop() { 
		this._sensorManager.unregisterListener(this);
	}

	@Override
	public void onAccuracyChanged(Sensor sensor, int accuracy) {

	}

	@Override
	public void onSensorChanged(SensorEvent event) {
		this._axis = event.values.clone();
	}
	
	public float[] GetAxisValues() {
		return this._axis;
	}
}
